<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\massage\model;

class CouponAtvCoupon extends \app\BaseModel
{
    protected $name = "massage_service_coupon_atv_coupon";
    public function dataAdd($data)
    {
        $res = $this->insert($data);
        return $res;
    }
    public function dataUpdate($dis, $data)
    {
        $res = $this->where($dis)->update($data);
        return $res;
    }
    public function shIng($cap_id)
    {
        $dis = ["cap_id" => $cap_id, "status" => 1];
        $count = $this->where($dis)->count();
        return $count;
    }
    public function dataList($dis, $page = 10)
    {
        $data = $this->where($dis)->order("id desc")->paginate($page)->toArray();
        return $data;
    }
    public function dataInfo($dis)
    {
        $data = $this->where($dis)->find();
        return !empty($data) ? $data->toArray() : [];
    }
    public function subSh($id, $goods_id)
    {
        $goods_list_model = new GoodsShList();
        $goods_model = new Goods();
        $list = $goods_model->where("id", "in", $goods_id)->select()->toArray();
        \think\facade\Db::startTrans();
        foreach ($list as $value) {
            $insert = ["uniacid" => $value["uniacid"], "sh_id" => $id, "goods_id" => $value["id"], "goods_name" => $value["goods_name"], "cover" => $value["cover"], "imgs" => !empty($value["imgs"]) ? implode(",", $value["imgs"]) : "", "text" => $value["text"], "cate_id" => $value["cate_id"]];
            $res = $goods_list_model->dataAdd($insert);
            if($res != 1) {
                \think\facade\Db::rollback();
                return ["code" => 500, "msg" => "提交失败"];
            }
            $goods_sh_id = $goods_list_model->getLastInsID();
            if(!empty($value["spe"])) {
                foreach ($value["spe"] as $v) {
                    $insert = ["uniacid" => $v["uniacid"], "sh_goods_id" => $goods_sh_id, "title" => $v["title"], "stock" => $v["stock"], "price" => $v["price"], "spe_id" => $v["id"]];
                    $res = \think\facade\Db::name("shequshop_school_goods_sh_spe")->insert($insert);
                    if($res != 1) {
                        \think\facade\Db::rollback();
                        return ["code" => 500, "msg" => "提交失败"];
                    }
                }
            }
        }
        $goods_model->where("id", "in", $goods_id)->update(["status" => 4]);
        \think\facade\Db::commit();
        return true;
    }
    public function couponCount($user_id)
    {
        $dis[] = ["user_id", "=", $user_id];
        $dis[] = ["status", "=", 1];
        $dis[] = ["end_time", ">", time()];
        $data = $this->where($dis)->count();
        return $data;
    }
}

?>